package com.example.app2024.svg;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.RectF;
import android.graphics.Region;

public class ProvinceItem
{
      private Path path;
      private  String name;
      private  int drawColor; //版块颜色
      private PointF clickPoint;  //显示省份信息

      public ProvinceItem(Path path)
      {
            this.path = path;
      }

      public Path getPath()
      {
            return path;
      }

      public void setPath(Path path)
      {
            this.path = path;
      }

      public String getName()
      {
            return name;
      }

      public void setName(String name)
      {
            this.name = name;
      }

      public int getDrawColor()
      {
            return drawColor;
      }

      public void setDrawColor(int drawColor)
      {
            this.drawColor = drawColor;
      }

      public PointF getClickPoint()
      {
            return clickPoint;
      }

      public void setClickPoint(PointF clickPoint)
      {
            this.clickPoint = clickPoint;
      }

      void  drawItem(Canvas canvas, Paint paint  , boolean isSelect)
      {
            if (isSelect)  //绘制内部 颜色
            {
                  paint.clearShadowLayer();
                  paint.setStrokeWidth(1);
                  paint.setColor(drawColor);
                  paint.setStyle(Paint.Style.FILL);
                  canvas.drawPath(path, paint);
                  //绘制边界
                  paint.setStyle(Paint.Style.STROKE);
                  paint.setStrokeWidth(6);
                  paint.setColor(0xff8EE91B);
                  canvas.drawPath(path, paint);
            }
            else
            {
                  paint.setStrokeWidth(10);
                  paint.setColor(Color.BLACK);
                  paint.setStyle(Paint.Style.FILL);
                  paint.setShadowLayer(8 , 0, 0, 0xffffff);
                  canvas.drawPath(path, paint);

                  paint.clearShadowLayer();
                  paint.setColor(drawColor);
                  paint.setStyle(Paint.Style.FILL);
                  canvas.drawPath(path, paint);

            }
      }

      /**
       * 判断当前点击区域是否在当前省份
       * @param x
       * @param y
       * @return
       */
      public  boolean isTouch(float x, float y )
      {
            RectF rectF = new RectF();
            path.computeBounds(rectF , true);
            Region region = new Region();
            region.setPath(path, new Region((int)rectF.left , (int)rectF.top, (int)rectF.right , (int)rectF.bottom));
            return  region.contains((int)x , (int)y);

      }
}
